import Vue from 'vue'
import store from '../store'
import cmd from '../config/Cmd'
const events = require('events')

class dongleManager extends events.EventEmitter {
  constructor () {
    super()
    this.connection = Vue.prototype.$socket
    this.cmd = cmd
    this.parse = function (str) {
      let res = []
      if (str.length !== 12) {

        return [0xff, 0xff, 0xff, 0xff, 0xff, 0xff]
      }
      for (let i = 0; i < str.length; i += 2) {

        let temp = str.substr(i, 2)
        res.push(eval('0x' + temp))
      }
      return res
    }
  }

  connectDeviceList () {
    this.connection.sendObj({
      'cmd': this.cmd.ADD_DEVICE,
      'para': store.getters.deviceMacList
    })
  }

}

export default dongleManager
